package main

func projectionArea(grid [][]int) int {
	temp := make([][]int, len(grid))

	for i := 0; i < len(grid); i++ {
		temp[i] = make([]int, len(grid[0]))
	}

	for i := 0; i < len(grid); i++ {
		for j := 0; j < len(grid); j++ {
			temp[i][j] += grid[i][j]
		}
	}

	getZX := func() int {
		zx := 0
		for i := 0; i < len(temp); i++ {
			for j := 0; j < len(temp[0]); j++ {
				if temp[i][j] > 0 {
					zx++
				}
			}
		}

		return zx
	}

	getXY := func() int {
		ret := 0

		for i := 0; i < len(temp[0]); i++ {
			max := 0
			for j := 0; j < len(temp); j++ {
				if temp[j][i] > max {
					max = temp[j][i]
				}
			}

			ret += max
		}

		return ret
	}

	getYZ := func() int {
		ret := 0
		for i := 0; i < len(temp); i++ {
			max := 0
			for j := 0; j < len(temp[0]); j++ {
				if temp[i][j] > max {
					max = temp[i][j]
				}
			}

			ret += max
		}

		return ret
	}

	ret := 0
	ret += getXY()
	ret += getYZ()
	ret += getZX()

	return ret
}

/*
@param
*/
